#ifndef BCTOOL_H
#define BCTOOL_H

#include <fstream>
#include <string>
#include <sstream>
//Definition of constants
#define MAXCELL 4000000
#define NUMVAR 2
#define NUMMUTPAR 19        // Number of mutation parameters

struct IMD
{
	std::string mdcrd;	// trajectory file.
    std::string cellpar; // cell parameter file.
    int N0;                 // Number of cells at the initial state.
	int seed;				// Seed of the random numbers.
	double dt;              // Dynamical parameters.
	double T1;              // Dynamical parameters, total time of simulation.
	int ntpx;                // Output the path result for every ntpx steps. if ntpx = 0, then no result is outputed. 

    double mutationrate;
    double varsigma;
public:
    void readParameters(const std::string& filename)
    {
        std::ifstream file(filename);

        // 读取并存储前两行字符串
        std::string line;

        // 跳过注释行，解析参数
        while (std::getline(file, line)) {
            // 使用stringstream来分割行
            std::istringstream iss(line);
            std::string key, value;
            if (std::getline(iss, key, '=')) {
                iss >> value;
                // 根据键值对填充结构体
                if (key == "N0") {
                    this->N0 = std::stoi(value);
                } else if (key == "dt") {
                    this->dt = std::stod(value);
                } else if (key == "T1") {
                    this->T1 = std::stoi(value);
                } else if (key == "ntpx") {
                    this->ntpx = std::stoi(value);
                } else if (key == "seed") {
                    this->seed = std::stoi(value);
                } else if (key == "cellpar") {
                    // 移除最前面和最后面一个字符
                    value = value.substr(1, value.size() - 2);
                    this->cellpar = value;
                } else if (key == "mdcrd") {
                    value = value.substr(1, value.size() - 2);
                    this->mdcrd = value;
                }else if (key == "varsigma") {
                    this->varsigma = std::stod(value);
                } else if (key == "mutationrate") {
                    this->mutationrate = std::stod(value);
                }
            }
        }
    }
    
};					    // MD parameters;

#endif